function makeStdTopo(D,dolog,magGrad,osldir)
%
% D - D object filename, or D object
% dolog - 1 to take log, 0 otherwise
% magGrad - 1 for combined grads, 0 for mags

if nargin > 3
    hasdir = 1;
else
    hasdir = 0;
    osldir = OSLDIR;
end

if ischar(D)
    D  = spm_eeg_load(D);
end

data = D.ftraw(0);

%% now shoehorn this data into fieldtrip format

% have added extra channels to the D-object.  Remove these...
data.label = data.label(1:330);
for iTrial = 1:numel(data.trial)
    data.trial{iTrial} = data.trial{iTrial}(1:330,:);
end

% make the grad info
grad = D.sensors('MEG');
data.grad = grad;

data.powspctrm = std(data.trial{1},[],2);

if dolog
    data.powspctrm = log(data.powspctrm);
end

data.freq = 10;
data.time = 1;
data.dimord = 'chan_freq_time';

cfg = [];
data = ft_combineplanar(cfg,data);

cfg = [];
cfg.baseline = 'no';
cfg.xlim         = [1 1];
cfg.ylim         = [10 10];

if magGrad
    cfg.layout      = [osldir '/layouts/neuromag306cmb.lay'];
else
    cfg.layout      = [osldir '/layouts/neuromag306mag.lay'];
end

ft_topoplotTFR(cfg,data);
